import request from './request'
import type { BeautyProduct, ProductCategory } from '@/types'

// 产品分类相关API
export const getCategories = (params?: any) => {
  return request({
    url: '/productCategory/list',
    method: 'post',
    params
  })
}

export const createCategory = (data: Partial<ProductCategory>) => {
  return request({
    url: '/productCategory/add',
    method: 'post',
    data
  })
}

export const updateCategory = (id: number, data: Partial<ProductCategory>) => {
  return request({
    url: `/productCategory/update`,
    method: 'post',
    data
  })
}

export const deleteCategory = (id: number) => {
  return request({
    url: `/productCategory/delete`,
    method: 'post',
    data: {
      id
    }
  })
}

// 产品相关API
export const getProducts = (params?: any) => {
  return request({
    url: '/product/page',
    method: 'post',
    data: {
      ...params
    }
  })
}

export const getProduct = (id: number) => {
  return request({
    url: `/product/detail`,
    method: 'get',
    params: {
      id
    }
  })
}

export const createProduct = (data: Partial<BeautyProduct>) => {
  return request({
    url: '/product/add',
    method: 'post',
    data
  })
}

export const updateProduct = (id: number, data: Partial<BeautyProduct>) => {
  return request({
    url: `/product/update`,
    method: 'post',
    data
  })
}

export const deleteProduct = (id: number) => {
  return request({
    url: `/product/delete`,
    method: 'post',
    data: {
      id
    }
  })
}